﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ELab.QuestionAnwer;

namespace ELab.Teacher.Controls
{
    public partial class ctrlTableAnswer : UserControl
    {
        public TestExampleResult testResult = null;
        public ctrlTableAnswer()
        {
            InitializeComponent();
            QADataGridView.AllowUserToAddRows = false;
            QADataGridView.AutoGenerateColumns = false;
        }
        public void ShowResult()
        {
            var Questions = testResult.Results.Select(r=>r.Question).ToList();
            for (int i = 0; i < Questions.Count; i++)
            {
                QADataGridView.Columns.Add(string.Format("Question{0}", i), Questions[i].QuestionValue);
            }

            for (int i = 0; i < Questions[0].Answers.Length; i++)
            {
                DataGridViewRow row = new DataGridViewRow();
                for (int j = 0; j < Questions.Count; j++)
                {
                    DataGridViewTextBoxCell cell = new DataGridViewTextBoxCell();
                    cell.Value = Questions[j].Answers[i].AnswerValue;
                    
                    row.Cells.Add(cell);
                }
                QADataGridView.Rows.Add(row);
            }
            QADataGridView.Refresh();
        }
    }
}
